package com.shop.operator.controller;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.shop.domain.CustomGoods;
import com.shop.domain.OperatorQueryGoodsVo;
import com.shop.domain.PageResult;
import com.shop.domain.Result;
import com.shop.model.Goods;
import com.shop.operator.service.OperatorGoodsService;

@Controller
@RequestMapping("/operatorGoodsAudited")
public class OperatorGoodsAction {
	@Resource
	private OperatorGoodsService operatorGoodsService;

	/**
	 * 显示待审核商品列表
	 * http://localhost:8080/Shopping/operatorGoodsAudited/showGoodsAuditedList.action
	 * @return
	 */
	@RequestMapping("/showGoodsAuditedList")
	public String showGoodsAuditedList() {

		return "operator/admin/goods";
	}

	/**
	 * 查找所有(未使用)
	 * 
	 * @return
	 */
	@RequestMapping("findAll")
	@ResponseBody
	public List<Goods> findAll() {
		List<Goods> goodsList = new ArrayList<Goods>();
		try {
			goodsList = this.operatorGoodsService.findAll();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return goodsList;
	}

	/**
	 * 找到分页(未使用)
	 * 
	 * @param page
	 *            页数
	 * @param size
	 *            页面大小
	 * @return
	 */
	@RequestMapping("/findPage")
	@ResponseBody
	public PageResult findPage(int page, int size) {
		PageResult pageResult = new PageResult();
		try {
			pageResult = operatorGoodsService.findPage(page, size);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return pageResult;
	}

	/**
	 * 根据名字模糊查找(分页显示)
	 * 
	 * @param goods
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping("/findPageByName")
	@ResponseBody
	public PageResult findPageByName(@RequestBody CustomGoods goods, int page, int size) {
		// System.out.println(goods);
		PageResult pageResult = new PageResult();
		try {
			pageResult = operatorGoodsService.findPageByName(goods, page, size);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return pageResult;
	}

	/**
	 * 批量修改商品的审核状态
	 * 
	 * @param ids
	 *            商品id集合
	 * @param status
	 *            审核状态
	 */
	@RequestMapping("/updateGoodsAuditedStatus")
	@ResponseBody
	public Result updateGoodsAuditedStatus(String ids, String status) {
		try {
			this.operatorGoodsService.updateGoodsStatus(ids, status);
			return new Result(true, "成功！");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return new Result(false, "失败！");
		}
	}

	/**
	 * 批量删除商品（逻辑删除）
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping("/deleteGoods")
	@ResponseBody
	public Result deleteGoods(String ids) {
		// System.out.println(ids);
		try {
			this.operatorGoodsService.deleteGoods(ids);
			return new Result(true, "成功！");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return new Result(false, "失败！");
		}
	}

	/**
	 * 显示商品详情
	 * 
	 * @return
	 */
	@RequestMapping("/showGoodsDetails")
	@ResponseBody
	public OperatorQueryGoodsVo showGoodsDetails(String id) {
		OperatorQueryGoodsVo operatorQueryGoodsVo = new OperatorQueryGoodsVo();
		try {
			operatorQueryGoodsVo = this.operatorGoodsService.findGoodsDetailsByid(id);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(operatorQueryGoodsVo);
		return operatorQueryGoodsVo;
	}
}
